#include "Param.h"
#include <QJsonDocument>

namespace Softwarer
{
	Query* Query::query()
	{
		return new Query();
	}
	Query* Query::addParam(const QString& key, int value)
	{
		m_query = QString::fromLocal8Bit("%1&%2=%3").arg(m_query).arg(key).arg(QString::number(value));
		return this;
	}

	Query* Query::addParam(const QString& key, bool value)
	{
		m_query = QString::fromLocal8Bit("%1&%2=%3").arg(m_query).arg(key).arg(value);
		return this;
	}

	Query* Query::addParam(const QString& key, const QString& value)
	{
		m_query = QString::fromLocal8Bit("%1&%2=%3").arg(m_query).arg(key).arg(value);
		return this;
	}
	QString Query::toQuery()
	{
		return m_query.right(m_query.length() - 1);
	}

	QByteArray IParam::toParam()
	{
		QJsonDocument document;
		document.setObject(m_valueObject);
		return document.toJson();
	}
	
	Param* Param::param() 
	{
		return new Param();
	}

	Param* Param::addParam(const QString& name, int value) 
	{
		m_valueObject[name] = value;
		return this;
	}

	Param* Param::addParam(const QString& name, const QString& value)
	{
		m_valueObject[name] = value;
		return this;
	}
}